//
//  YBNewsNavController.m
//  Cocoachina
//
//  Created by 尚往文化 on 17/9/13.
//  Copyright © 2017年 YBing. All rights reserved.
//

#import "YBNewsNavController.h"
#import "YBNewsController.h"
#import "Define.h"
#import "YBRecommendNewsController.h"
#import "YBSearchController.h"

@interface YBNewsNavController ()

@end

@implementation YBNewsNavController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI
{
    [self setupNavigationBar];
    [self setupItems];
    [self setupSearchButton];
}

- (void)setupNavigationBar
{
    UIView *statusBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 20)];
    statusBar.backgroundColor = kNavColor;
    [self.view addSubview:statusBar];
    
    self.navigationItem.title = @"";
}

- (void)setupSearchButton
{
    UIView *navMenuView = [self valueForKey:@"navMenuView"];
    navMenuView.width -= 60;
    
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.backgroundColor = kNavColor;
    searchBtn.frame = CGRectMake(kScreenW-60, 20, 60, navMenuView.height);
    [searchBtn setImage:[UIImage imageWithText:@"\U0000e620" color:[UIColor whiteColor] size:CGSizeMake(25, 25)] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:searchBtn];
}

- (void)setupItems
{
    NSMutableArray *items = [NSMutableArray array];
    [items addObject:[YBBaseMenuControllerItem itemWithTitle:@"推荐" vc:[YBRecommendNewsController new]]];
    NSArray *urls = @[@"http://www.cocoachina.com/ios/list_69_", @"http://www.cocoachina.com/swift/list_73_", @"http://www.cocoachina.com/appstore/list_72_", @"http://www.cocoachina.com/design/list_77_", @"http://www.cocoachina.com/review/list_82_", @"http://www.cocoachina.com/vr/list_84_", @"http://www.cocoachina.com/game/list_68_", @"http://www.cocoachina.com/apple/list_70_", @"http://www.cocoachina.com/android/list_83_", @"http://www.cocoachina.com/market/list_74_", @"http://www.cocoachina.com/industry/list_75_", @"http://www.cocoachina.com/programmer/list_71_"];
    NSArray *titles = @[@"iOS开发", @"Swift", @"App Store研究", @"产品设计", @"应用", @"VR", @"游戏开发", @"苹果相关", @"安卓相关", @"营销推广", @"业界动态", @"程序人生"];
    for (int i=0; i<urls.count; i++) {
        YBNewsController *vc = [YBNewsController new];
        vc.url = urls[i];
        YBBaseMenuControllerItem *item = [YBBaseMenuControllerItem itemWithTitle:titles[i] vc:vc];
        [items addObject:item];
    }
    
    self.items = items;
}

- (void)search
{
    [self.navigationController pushViewController:[YBSearchController new] animated:NO];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}


@end
